<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class QnewsController extends Controller
{
	public $layout = "application.views.layouts._admin";

	public function actionAdd()
	{
		if((isset($_POST['title']))&&(isset($_POST['redactor_content'])))
		{
			$news=new news();
			$news->title=$_POST['title'];
			$news->text=$_POST['redactor_content'];
                        $news->date=date('Y-m-d');

			if ($news->save())
			{
				$this->redirect(array('_list'));
			}
			else
			{
				$this->redirect('error');
			}
		}


		$this->render('application.views.qnews._add');
	}

	public function actionList()
	{
		$news=news::model()->findAll();
		$this->render('application.views.qnews._list',array("news"=>$news));
	}

	public function actionDel()
	{
		$news_id=$_GET['id'];
		news::model()->deleteAll("id_news=:id_news",array("id_news"=>$news_id));
		$this->redirect('/admin/qnews/_list');
	}

	public function actionEdit()
	{
		$news_id=$_GET['id'];
		$news=news::model()->findByPk($news_id);
		$this->render('application.views.qnews._edit',array('news'=>$news));
	}

	public function actionUpdate()
	{
		if ((isset($_POST['id']))&&(isset($_POST['title']))&&(isset($_POST['redactor_content'])))
		{
			$news=news::model()->findByPk($_POST['id']);
			$news->title=$_POST['title'];
			$news->text=$_POST['redactor_content'];

			if ($news->save())
			{
				$this->redirect(array('_list'));
			}
			else
			{
				$this->redirect('error');
			}
		}
	}

}
?>
